package com.hskn.hss.module.cases.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.controller.BaseController;
import com.hskn.hss.core.domain.BaseEntity;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.core.utils.poi.ExcelUtil;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.alarmcar.entity.AlarmCar;
import com.hskn.hss.module.carTrack.entity.CarTrack;
import com.hskn.hss.module.cases.entity.Cases;
import com.hskn.hss.module.cases.entity.CasesFull;
import com.hskn.hss.module.cases.ex.vo.*;
import com.hskn.hss.module.cases.mapper.CasesMapper;
import com.hskn.hss.module.cases.service.ICasesService;
import com.hskn.hss.module.cases.to.EventDistributionTO;
import com.hskn.hss.module.cases.vo.ProblemSourceVO;
import com.hskn.hss.module.cases.vo.ProblemTypeTableVO;
import com.hskn.hss.module.cases.vo.TimelyAnalysisTableVO;
import com.hskn.hss.module.menu.mapper.SysMenuMapper;
import com.hskn.hss.module.tlemployee.entity.TIEmployeeVo;
import com.hskn.hss.utils.Tools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-18
 */
@Slf4j
@RestController
@RequestMapping("/hss/cases")
@Api(tags = {"-cases"}, description = "事件")
public class CasesController extends BaseController {

    @Autowired
    private ICasesService casesService;

    @RequestMapping(value = "amount", method = RequestMethod.POST)
    public AjaxResult<Object> amount(HttpServletRequest request) {
        try {
            BaseEntity entity=new BaseEntity();
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            List<JSONObject> json = casesService.amount(entity, params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @RequestMapping(value = "list", method = RequestMethod.POST)
    public AjaxResult<Object> list(HttpServletRequest request) {
        try {
            BaseEntity entity = new BaseEntity();
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = casesService.mList(entity, params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @RequestMapping(value = "applist", method = RequestMethod.POST)
    public AjaxResult<Object> applist(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            JSONObject json = casesService.appmList(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.INSERT, tableName = "cases", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public AjaxResult<Object> add(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.add(params);
            return AjaxResult.success("发布成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "cases", idKey = "caseId", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public AjaxResult<Object> update(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.mUpdate(params);
            return AjaxResult.success("修改成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "cases", idKey = "caseIds", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "del", method = RequestMethod.POST)
    public AjaxResult<Object> del(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.del(params);
            return AjaxResult.success("删除成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @RequestMapping(value = "detail", method = RequestMethod.POST)
    public AjaxResult<Object> detail(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            CasesFull casesFull = casesService.detail(params);
            return AjaxResult.success(casesFull);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "cases", idKey = "caseId", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "archive", method = RequestMethod.POST)
    public AjaxResult<Object> archive(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.archive(params);
            return AjaxResult.success("归档成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "cases", idKey = "caseIds", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "jiean", method = RequestMethod.POST)
    public AjaxResult<Object> jiean(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.jiean(params);
            return AjaxResult.success("结案成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "cases", idKey = "caseIds", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "cuiban", method = RequestMethod.POST)
    public AjaxResult<Object> cuiban(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.cuiban(params);
            return AjaxResult.success("催办成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "cases", idKey = "caseIds", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "feiqi", method = RequestMethod.POST)
    public AjaxResult<Object> feiqi(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.feiqi(params);
            return AjaxResult.success("废弃成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "cases", idKey = "caseId", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "huifu", method = RequestMethod.POST)
    public AjaxResult<Object> huifu(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.huifu(params);
            return AjaxResult.success("恢复成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "cases", idKey = "caseId", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "gaipai", method = RequestMethod.POST)
    public AjaxResult<Object> gaipai(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.gaipai(params);
            return AjaxResult.success("改派成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "cases", idKey = "caseId", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "chuli", method = RequestMethod.POST)
    public AjaxResult<Object> chuli(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.chuli(params);
            return AjaxResult.success("处理成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "cases", idKey = "caseId", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "assigned", method = RequestMethod.POST)
    public AjaxResult<Object> assigned(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.assigned(params);
            return AjaxResult.success("分派成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "cases", idKey = "caseId", bean = Cases.class, beanMapper = CasesMapper.class, names = "createName")
    @RequestMapping(value = "qiandao", method = RequestMethod.POST)
    public AjaxResult<Object> qiandao(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesService.qiandao(params);
            return AjaxResult.success("签到成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }


    @RequestMapping(value = "autoAssign", method = RequestMethod.POST)
    public AjaxResult<Object> autoAssign(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            TIEmployeeVo tiEmployeeVo = casesService.autoAssign(params);
            return AjaxResult.success(tiEmployeeVo);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    /**
     * 事件分布 问题类型柱状图
     *
     * @param eventDistributionTO
     * @return
     */
    @ApiOperation(value = " 事件分布 问题类型柱状图", notes = " 事件分布 问题类型柱状图")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok")
    })
    @RequestMapping(value = "getProblemTypeHistogramEChars", method = RequestMethod.POST)
    public AjaxResult getProblemTypeHistogramEChars(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            return AjaxResult.success(casesService.getProblemTypeHistogramEChars(eventDistributionTO));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 事件分布 时间走势折线图
     *
     * @param eventDistributionTO
     * @return
     */
    @ApiOperation(value = "事件分布 时间走势折线图", notes = "事件分布 时间走势折线图")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok")
    })
    @RequestMapping(value = "getDistributionTimeTrendEChars", method = RequestMethod.POST)
    public AjaxResult getDistributionTimeTrendEChars(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            return AjaxResult.success(casesService.getDistributionTimeTrendEChars(eventDistributionTO));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 事件分布 来源统计列表
     *
     * @param eventDistributionTO
     * @return
     */
    @ApiOperation(value = "事件分布 来源统计列表", notes = "事件分布 来源统计列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok",response= ProblemSourceVO.class )
    })
    @RequestMapping(value = "getProblemSourceTable", method = RequestMethod.POST)
    public AjaxResult getProblemSourceTable(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            return AjaxResult.success(casesService.getProblemSourceTable(eventDistributionTO));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }
    /**
     * 事件分布 来源统计列表
     *
     * @param eventDistributionTO
     * @return
     */
    @ApiOperation(value = "事件分布 问题类型列表", notes = "事件分布 问题类型列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok",response = ProblemTypeTableVO.class)
    })
    @RequestMapping(value = "getProblemTypeTableVOTable", method = RequestMethod.POST)
    public AjaxResult getProblemTypeTableVOTable(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            return AjaxResult.success(casesService.getProblemTypeTableVOTable(eventDistributionTO));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }
    /**
     * 处理情况 折线图
     * @param eventDistributionTO
     * @return
     */
    @ApiOperation(value = "处理情况 折线图", notes = "处理情况 折线图")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok",response = ProblemTypeTableVO.class)
    })
    @RequestMapping(value = "getTreatmentEChars", method = RequestMethod.POST)
    public AjaxResult getTreatmentEChars(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            return AjaxResult.success(casesService.getTreatmentEChars(eventDistributionTO));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }
    /**
     * 处理情况 列表
     * @param eventDistributionTO
     * @return
     */
    @ApiOperation(value = "处理情况列表", notes = "处理情况列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok",response = ProblemTypeTableVO.class)
    })
    @RequestMapping(value = "getTreatmentTable", method = RequestMethod.POST)
    public AjaxResult getTreatmentTable(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            return AjaxResult.success(casesService.getTreatmentTable(eventDistributionTO));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }
    /**
     *  及时分析统计图
     * @param eventDistributionTO
     * @return
     */
    @ApiOperation(value = "及时分析统计图", notes = "及时分析统计图")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok")
    })
    @RequestMapping(value = "getTimelyAnalysisEChars", method = RequestMethod.POST)
    public AjaxResult getTimelyAnalysisEChars(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            return AjaxResult.success(casesService.getTimelyAnalysisEChars(eventDistributionTO));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }
    /**
     *  及时分析列表
     * @param eventDistributionTO
     * @return
     */
    @ApiOperation(value = "及时分析列表", notes = "及时分析列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok",response = TimelyAnalysisTableVO.class)
    })
    @RequestMapping(value = "getTimelyAnalysisTable", method = RequestMethod.POST)
    public AjaxResult getTimelyAnalysisTable(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            return AjaxResult.success(casesService.getTimelyAnalysisTable(eventDistributionTO));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 时间走势折线图
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "selectCaseForLineChartBTable", method = RequestMethod.POST)
    public AjaxResult selectCaseForLineChartBTable(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                return AjaxResult.success(casesService.selectCaseForLineChartBTable(cases));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 来源统计表格
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "selectCaseForDepartCount", method = RequestMethod.POST)
    public AjaxResult selectCaseForDepartCount(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                if (params.containsKey("pageSize") && params.containsKey("pageNum")) {
                    startPage(params.getInteger("pageNum"), params.getInteger("pageSize"));
                }
                return AjaxResult.success(Tools.getDataTable(casesService.selectCaseForDepartCount(cases)));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 问题类型统计表格
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "selectCaseForcaseIssueCount", method = RequestMethod.POST)
    public AjaxResult selectCaseForcaseIssueCount(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                if (params.containsKey("pageSize") && params.containsKey("pageNum")) {
                    startPage(params.getInteger("pageNum"), params.getInteger("pageSize"));
                }
                return AjaxResult.success(Tools.getDataTable(casesService.selectCaseForcaseIssueCount(cases)));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 处理情况统计表格
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "selectCaseForOverCount", method = RequestMethod.POST)
    public AjaxResult selectCaseForOverCount(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                if (params.containsKey("pageSize") && params.containsKey("pageNum")) {
                    startPage(params.getInteger("pageNum"), params.getInteger("pageSize"));
                }
                return AjaxResult.success(Tools.getDataTable(casesService.selectCaseForOverCount(cases)));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 处理情况统计柱状图
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "selectCaseForOverBTable", method = RequestMethod.POST)
    public AjaxResult selectCaseForOverBTable(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                return AjaxResult.success(casesService.selectCaseForOverBTable(cases));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 按机构查询及时分析表格
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "selectCaseForTimelyAnalyse", method = RequestMethod.POST)
    public AjaxResult selectCaseForTimelyAnalyse(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                if (params.containsKey("pageSize") && params.containsKey("pageNum")) {
                    startPage(params.getInteger("pageNum"), params.getInteger("pageSize"));
                }
                return AjaxResult.success(Tools.getDataTable(casesService.selectCaseForTimelyAnalyse(cases)));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 按负责人统计-问题类型柱状图
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "eventPersonByType", method = RequestMethod.POST)
    public AjaxResult selectCaseForBTableByPersonId(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                return AjaxResult.success(casesService.eventPersonByType(cases));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 按负责人统计-时间走势折线图
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "eventPersonByTime", method = RequestMethod.POST)
    public AjaxResult selectCaseForLineChartBTableByPersonId(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                return AjaxResult.success(casesService.eventPersonByTime(cases));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 按负责人统计-来源统计表格
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "eventPersonByCreater", method = RequestMethod.POST)
    public AjaxResult selectCaseForDepartCountByPersonId(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                return AjaxResult.success(casesService.eventPersonByCreater(cases));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 按负责人统计-问题类型统计表格
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "eventPersonByProblem", method = RequestMethod.POST)
    public AjaxResult selectCaseForcaseIssueCountByPersonId(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                return AjaxResult.success(casesService.eventPersonByProblem(cases));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 处理情况统计柱状图
     * @param request
     * @return
     */
    @RequestMapping(value = "eventPersonTreatment", method = RequestMethod.POST)
    public AjaxResult eventPersonTreatment(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                return AjaxResult.success(casesService.eventPersonTreatment(cases));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 按负责人统计-处理情况统计表格
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "eventPersonTreatmentTable", method = RequestMethod.POST)
    public AjaxResult eventPersonTreatmentTable(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                return AjaxResult.success(casesService.eventPersonTreatmentTable(cases));
            } else {
                return AjaxResult.fail("参数传输失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 处理及时分析柱状图
     * @param
     * @return
     */
    @RequestMapping(value = "eventPersonAnalysis", method = RequestMethod.POST)
    public AjaxResult eventPersonAnalysis(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            return AjaxResult.success(casesService.eventPersonAnalysis(eventDistributionTO));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 按负责人统计-及时分析表格
     *
     * @param
     * @return
     */
    @RequestMapping(value = "eventPersonAnalysisTable", method = RequestMethod.POST)
    public AjaxResult eventPersonAnalysisTable(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            return AjaxResult.success(casesService.eventPersonAnalysisTable(eventDistributionTO));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 巡查案件列表导出
     * @param
     * @return
     */
    @ApiOperation(value = "巡查案件列表导出", notes = "巡查案件列表导出")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok",response = ProblemTypeTableVO.class)
    })
    @RequestMapping(value = "casesListExcel", method = RequestMethod.POST)
    public com.hskn.hss.core.domain.AjaxResult casesListExcel(HttpServletRequest request) {
        try {
            BaseEntity entity = new BaseEntity();
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                List<CasesTableExcel> oilDeviceServiceVOList =
                        JSONArray.parseArray(JSONObject.toJSONString(casesService.casesTableListExcel(entity, params)), CasesTableExcel.class);
                //工具类实例化
                ExcelUtil<CasesTableExcel> util = new ExcelUtil<>(CasesTableExcel.class);
                //导出
                return util.exportExcel(oilDeviceServiceVOList, "巡查案件");
            } else {
                return com.hskn.hss.core.domain.AjaxResult.error();
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return com.hskn.hss.core.domain.AjaxResult.error();
        }
    }

    /**
     * 处理情况列表(按责任机构统计)导出
     * @param eventDistributionTO
     * @return
     */
    @ApiOperation(value = "处理情况列表(按责任机构统计)导出", notes = "处理情况列表(按责任机构统计)导出")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok",response = ProblemTypeTableVO.class)
    })
    @RequestMapping(value = "getTreatmentTableExcel", method = RequestMethod.POST)
    public com.hskn.hss.core.domain.AjaxResult getTreatmentTableExcel(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            if(eventDistributionTO.getDepNames() == null || eventDistributionTO.getDepNames().size()>0){
            List<TreatmentExcelVO> oilDeviceServiceVOList =
                    JSONArray.parseArray(JSONObject.toJSONString(casesService.getTreatmentTableExcel(eventDistributionTO)), TreatmentExcelVO.class);
            //工具类实例化
            ExcelUtil<TreatmentExcelVO> util = new ExcelUtil<>(TreatmentExcelVO.class);
            //导出
            return util.exportExcel(oilDeviceServiceVOList, "处理情况列表(按责任机构统计)");
            }else{
                return com.hskn.hss.core.domain.AjaxResult.error("请选择至少一条数据导出");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return com.hskn.hss.core.domain.AjaxResult.error();
        }
    }
    /**
     *  及时分析列表(按责任机构统计)导出
     * @param eventDistributionTO
     * @return
     */
    @ApiOperation(value = "及时分析列表(按责任机构统计)导出", notes = "及时分析列表(按责任机构统计)导出")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok",response = TimelyAnalysisTableVO.class)
    })
    @RequestMapping(value = "getTimelyAnalysisExcel", method = RequestMethod.POST)
    public com.hskn.hss.core.domain.AjaxResult getTimelyAnalysisExcel(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            if(eventDistributionTO.getDepNames() == null || eventDistributionTO.getDepNames().size()>0){
            List<TimelyAnalysisExcelVO> oilDeviceServiceVOList =
                    JSONArray.parseArray(JSONObject.toJSONString(casesService.getTimelyAnalysisTableExcel(eventDistributionTO)), TimelyAnalysisExcelVO.class);
            //工具类实例化
            ExcelUtil<TimelyAnalysisExcelVO> util = new ExcelUtil<>(TimelyAnalysisExcelVO.class);
            //导出
            return util.exportExcel(oilDeviceServiceVOList, "及时分析列表(按责任机构统计)");
            } else{
                return com.hskn.hss.core.domain.AjaxResult.error("请选择至少一条数据导出");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return com.hskn.hss.core.domain.AjaxResult.error();
        }
    }

    /**
     * 按负责人统计-处理情况统计表格导出
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "eventPersonTreatmentExcel", method = RequestMethod.POST)
    public com.hskn.hss.core.domain.AjaxResult eventPersonTreatmentExcel(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                if(cases.getPersonIds() == null ||cases.getPersonIds().size()>0) {
                    List<CasesTableExcel> oilDeviceServiceVOList =
                            JSONArray.parseArray(JSONObject.toJSONString(casesService.eventPersonTreatmentTableExcel(cases)), CasesTableExcel.class);
                    //工具类实例化
                    ExcelUtil<CasesTableExcel> util = new ExcelUtil<>(CasesTableExcel.class);
                    //导出
                    return util.exportExcel(oilDeviceServiceVOList, "处理情况统计表(按负责人统计)");
                }else{
                    return com.hskn.hss.core.domain.AjaxResult.error("请选择至少一条数据导出");
                }
            } else {
                return com.hskn.hss.core.domain.AjaxResult.error();
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return com.hskn.hss.core.domain.AjaxResult.error();
        }

    }
    /**
     * 按负责人统计-及时分析表格
     *
     * @param
     * @return
     */
    @RequestMapping(value = "eventPersonAnalysisTableExcel", method = RequestMethod.POST)
    public com.hskn.hss.core.domain.AjaxResult eventPersonAnalysisTableExcel(@RequestBody @Validated EventDistributionTO eventDistributionTO) {
        try {
            if(eventDistributionTO.getPersonIds() == null || eventDistributionTO.getPersonIds().size()>0) {
                List<TimelyAnalysisExcel2VO> oilDeviceServiceVOList =
                        JSONArray.parseArray(JSONObject.toJSONString(casesService.eventPersonAnalysisTableExcel(eventDistributionTO)), TimelyAnalysisExcel2VO.class);
                //工具类实例化
                ExcelUtil<TimelyAnalysisExcel2VO> util = new ExcelUtil<>(TimelyAnalysisExcel2VO.class);
                //导出
                return util.exportExcel(oilDeviceServiceVOList, "及时分析表(按负责人统计)");
            }else{
                return com.hskn.hss.core.domain.AjaxResult.error("请选择至少一条数据导出");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return com.hskn.hss.core.domain.AjaxResult.error();
        }
    }

    /**
     * 按事件分布-来源统计表格导出
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "eventPersonByCreaterExcel", method = RequestMethod.POST)
    public com.hskn.hss.core.domain.AjaxResult eventPersonByCreaterExcel(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                if(cases.getCreateUids() == null || cases.getCreateUids().size()>0){
                List<CasesTableExcel2> oilDeviceServiceVOList =
                        JSONArray.parseArray(JSONObject.toJSONString(casesService.eventPersonByCreaterExcel(cases)), CasesTableExcel2.class);
                //工具类实例化
                ExcelUtil<CasesTableExcel2> util = new ExcelUtil<>(CasesTableExcel2.class);
                //导出
                return util.exportExcel(oilDeviceServiceVOList, "来源统计表(按事件分布统计)");
                }else{
                    return com.hskn.hss.core.domain.AjaxResult.error("请选择至少一条数据导出");
                }
            } else {
                return com.hskn.hss.core.domain.AjaxResult.error();
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return com.hskn.hss.core.domain.AjaxResult.error();
        }
    }

    /**
     * 按事件分布统计-问题类型统计表格
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "eventPersonByProblemExcel", method = RequestMethod.POST)
    public com.hskn.hss.core.domain.AjaxResult eventPersonByProblemExcel(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            if (params != null) {
                Cases cases = JSONObject.parseObject(params.toJSONString(), Cases.class);
                if(cases.getCreateUids() == null || cases.getCreateUids().size()>0) {
                    List<CasesTableExcel3> oilDeviceServiceVOList =
                            JSONArray.parseArray(JSONObject.toJSONString(casesService.eventPersonByProblemExcel(cases)), CasesTableExcel3.class);
                    //工具类实例化
                    ExcelUtil<CasesTableExcel3> util = new ExcelUtil<>(CasesTableExcel3.class);
                    //导出
                    return util.exportExcel(oilDeviceServiceVOList, "问题类型统计表(按事件分布统计)");
                } else{
                    return com.hskn.hss.core.domain.AjaxResult.error("请选择至少一条数据导出");
                }
            } else {
                return com.hskn.hss.core.domain.AjaxResult.error();
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return com.hskn.hss.core.domain.AjaxResult.error();
        }
    }
}

